package com.yanqu.road.server.cmd.blacklist;

import com.yanqu.road.server.cmd.base.AbstractServerCommand;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.player.BlacklistProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.pb.PlayerPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/4/6 17:59
 */
@Cmd(code = GameProtocol.S_BLACKLIST_GET_USER_INFO_CROSS, desc = "跨服下来获取被拉黑的玩家的信息")
public class GetBlacklistUserInfoCmd extends AbstractServerCommand {
    private long fromUserId;
    private long fromUserServerId;
    private int type;
    private long blackUserId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BlacklistProto.BlacklistAddCrossReqMsg reqMsg = BlacklistProto.BlacklistAddCrossReqMsg.parseFrom(packet.getBytes());
        fromUserId = reqMsg.getUserId();
        fromUserServerId = reqMsg.getServerId();
        type = reqMsg.getType();
        blackUserId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        BlacklistProto.BlacklistAddCrossRespMsg.Builder respMsg = BlacklistProto.BlacklistAddCrossRespMsg.newBuilder();
        respMsg.setBaseUserInfo(PlayerPb.parsePlayerBaseTempMsg(UserMgr.getUserInfo(blackUserId)));
        respMsg.setFromUserId(fromUserId);
        respMsg.setFromUserServerId(fromUserServerId);
        respMsg.setBlackUserId(blackUserId);
        respMsg.setType(type);
        YanQuMessage yqMsg = YanQuMessageUtils.buildMessage(Protocol.C_CROSS_ADD_BLACK_LIST_GET_USER_INFO_RESP, respMsg);
        GamePlayerMgr.sendPacket(blackUserId, yqMsg);
    }

    @Override
    public void sendData(YanQuMessage packet) throws Exception {

    }
}
